﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Classes
{
	public class DBVehiculos
	{
		IList<Vehiculo> _listVehiculos;

		public DBVehiculos()
		{
			this._listVehiculos = new List<Vehiculo>();
			this._listVehiculos.Add(new Vehiculo("AAA001", "qwdqw1", "1", "BMW", "Z3", DateTime.Parse("11-11-2011"),new Scoring("DesInicial",1)));
            this._listVehiculos.Add(new Vehiculo("AAA002", "qwdqw2", "2", "FORD", "SIERRA", DateTime.Parse("12-11-2011"), new Scoring("DesInicial", 1)));
            this._listVehiculos.Add(new Vehiculo("AAA003", "qwdqw3", "3", "CHEVROLET", "PRISMA", DateTime.Parse("09-11-2011"), new Scoring("DesInicial", 1)));
            this._listVehiculos.Add(new Vehiculo("AAA004", "qwdqw4", "4", "AUDI", "C4", DateTime.Parse("1-11-2011"), new Scoring("DesInicial", 1)));
            this._listVehiculos.Add(new Vehiculo("AAA005", "qwdqw4", "5", "AUDI", "C3", DateTime.Parse("8-11-2011"), new Scoring("DesInicial", 1)));
		}


        public void AgregarVehiculo(Vehiculo v)
        {
            this._listVehiculos.Add(v);

        }

        
        public IList<Vehiculo> GetListVehiculos()
		{
			return this._listVehiculos;
		}


		public Vehiculo GetVehiculo(string patente)
		{
			foreach (Vehiculo v in this._listVehiculos)
			{
				if (v.Patente == patente)
				{
					return v;
				}
			}

			return null;
		}


		public bool GetEquipoVehiculoCompatibility(Vehiculo v, string modeloEquipo)
		{
			IDictionary<string, IList<string>> compatibilityList = new Dictionary<string, IList<string>>();

			compatibilityList["Z3"] = new List<string>();
			compatibilityList["Z3"].Add("Mod1");
			compatibilityList["Z3"].Add("Mod2");

			compatibilityList["PRISMA"] = new List<string>();
			compatibilityList["PRISMA"].Add("Mod3");
			compatibilityList["PRISMA"].Add("Mod4");

			compatibilityList["C4"] = new List<string>();
			compatibilityList["C4"].Add("Mod5");
			compatibilityList["C4"].Add("Mod6");

			try
			{
				return compatibilityList[v.Modelo].Contains(modeloEquipo);
			}
			catch (Exception)
			{
				return false;
			}
		}

		//public Scoring GetScoring(string patente)
		//{
		//    //IDictionary<string, Scoring> vehicleList = new Dictionary<string, Scoring>();

		//    //vehicleList["AA001"] = new Scoring("Regular", 10);
		//    //vehicleList["AA002"] = new Scoring("Bueno", 25);
		//    //vehicleList["AA003"] = new Scoring("Peligroso", 5);

		//    //try
		//    //{
		//    //    return vehicleList[patente];
		//    //}
		//    //catch (Exception)
		//    //{
		//    //    return null;
		//    //}
		//    foreach (Vehiculo v in this._listVehiculos)
		//    {
		//        if (v.Patente == patente)
		//        {
		//            return v.Scoring;
		//        }
		//    }

		//    return null;
		//}


        public bool VehiculoExistente(Vehiculo v)
        {
            List<Vehiculo> lVehiculos = (List<Vehiculo>)this.GetListVehiculos();

            int cant = lVehiculos.Count();
            //Console.WriteLine(cant);
            for (int i = 0; i < cant; i++)
            {
                String p = lVehiculos.ElementAt(i).Patente;
                if ((v.Patente) == p)
                {
                    return true;
                }
            }
            return false;
        }

        public void MostrarListaVehiculos()
        {
             List<Vehiculo> lVehiculos = (List<Vehiculo>)this.GetListVehiculos();

                int cant = lVehiculos.Count();
                for (int i = 0; i < cant; i++)
                {
                    lVehiculos.ElementAt(i).ImprimirDatos();
                    Console.WriteLine("Presione ENTER para el Siguiente");
                    Console.ReadKey();
                }
        }

		public bool ActualizaVehiculo(Vehiculo v)
		{
			return false;
		}
	}
}